<template>
  <div class="mod-config">
    <el-form :inline="true" :model="searchForm" @keyup.enter.native="queryList()">

      <el-form-item>
        <el-input v-model="searchForm.appJarName" placeholder="应用名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-select v-model="searchForm.execStatus" filterable placeholder="请选择执行状态" style="width:100%">
          <el-option label="全部" value="" ></el-option>
          <template v-for="(item, index) in dict.ExecStatus">
            <el-option :label="item.value +': '+ item.label" :value="item.value"></el-option>
          </template>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-input v-model="searchForm.agentIpv4" placeholder="代理实例IP" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <!--<el-input v-model="searchForm.execDate" placeholder="执行日期" clearable></el-input>-->
        <el-date-picker
          v-model="searchForm.execDate"
          type="date"
          value-format="yyyyMMdd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="queryList(1)">查询</el-button>
        <!--        <el-button type="" @click="addEntity()">新增</el-button>
                <el-button type="danger" @click="deleteEntity()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>

    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column prop="appJarName" label="应用名称" header-align="center" align="center" width="200"></el-table-column>
      <el-table-column prop="execDate" label="执行日期" header-align="center" align="center" width="100"></el-table-column>
      <el-table-column prop="agentIpv4" label="代理实例IP" header-align="center" align="center"></el-table-column>
      <el-table-column prop="execStatus" label="执行状态" header-align="center" align="center">
        <template slot-scope="scope">
          <el-tooltip placement="bottom-end">
            <div slot="content">{{scope.row.execResult}}</div>
            <template v-for="(item, index) in dict.ExecStatus">
              <el-tag v-if="item.value == scope.row.execStatus" :type="item.style">
                {{item.value}}: {{item.label}}
              </el-tag>
            </template>
          </el-tooltip>
        </template>
      </el-table-column>

      <el-table-column prop="startupTime" label="启动时间" header-align="center" align="center"></el-table-column>
      <el-table-column prop="endTime" label="结束时间" header-align="center" align="center"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template slot-scope="scope">
          <!--             	<el-button type="text" size="small" @click="modEntity(scope.row)">编辑</el-button>-->
          <el-button type="text" size="small" @click="showDetail(scope.row)">明细</el-button>
          <!--                <el-button type="text" size="small" @click="deleteEntity(scope.row.id)">删除</el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="page"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
<!--    <add-entity v-if="addEntityVisible" ref="addEntity" @refreshDataList="queryList"></add-entity>
    <mod-entity v-if="modEntityVisible" ref="modEntity" @refreshDataList="queryList"></mod-entity>-->
    <show-detail v-if="showDetailVisible" ref="showDetail"></show-detail>
  </div>
</template>

<script>
  //import AddEntity from './agentExecLogList-add'
  //import ModEntity from './agentExecLogList-mod'
  // import ShowDetail from './agent-exec1-log-detail'
  import ShowDetail from './agent-job-log-detail'
  import {mapState} from "vuex";

  export default {
    data() {
      return {
        isShow: false,
        searchForm: {},
        dataList: [],
        page: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addEntityVisible: false,
        modEntityVisible: false,
        showDetailVisible: false,

      }
    },
    components: {
      //AddEntity, ModEntity,
      ShowDetail
    },
    activated() {
      this.queryList()
    },
    computed: mapState({
      // listType: state => state.goods.listType
    }),
    mounted() {
      // 数据字典查询
      //this.getSelectDict('FlowType').then((res) => {
      //  this.$store.commit('goods/updateListType', res)
      //})
    },
    methods: {
      // 获取数据列表
      queryList(clr) {
        if (typeof (clr) != 'undefined') {
          this.page = 1
        }
        this.dataListLoading = true
        let obj = {
          'page': this.page,
          'size': this.pageSize,
          //isTrans: true,
          //transParams: ['FlowType', 'ApplyResult', 'ReceiveStatus'],
          //transDict: ['flowType', 'applyResult', 'receiveStatus']
        }
        obj = Object.assign(obj, this.searchForm)
        this.getTableList('/api/agent/exec/logs', obj, (data) => {
          this.dataListLoading = false
          if (data.code == '000000' && data.rows && data.rows.length > 0) {
            this.dataList = data.rows
            this.totalPage = data.total
          } else {
            this.dataList = []
            this.totalPage = 0
          }
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.page = 1
        this.queryList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.page = val
        this.queryList()
      },
      // 多选
      selectionChangeHandle(val) {
        this.dataListSelections = val
      },
      // 新增
      // addEntity() {
      //   this.addEntityVisible = true
      //   this.$nextTick(() => {
      //     this.$refs.addEntity.init()
      //   })
      // },
      // 修改
      // modEntity(row) {
      //   let cloneData = Object.assign({}, row)
      //   this.modEntityVisible = true
      //   this.$nextTick(() => {
      //     this.$refs.modEntity.init(cloneData)
      //   })
      // },
      showDetail(row) {
        let cloneData = Object.assign({}, row)
        this.showDetailVisible = true
        this.$nextTick(() => {
          this.$refs.showDetail.init(cloneData.id, cloneData)
        })
      },
      // 删除
      deleteEntity(id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行删除操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let obj = {"ids": ids}
          this.getTableList('/api/agentExecLogListDel', obj, (res) => {
            if (res && res.code === '000000') {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1000,
                onClose: () => {
                  this.queryList()
                }
              })
            } else {
              this.$message.error(res.rsmsg)
            }
          })
        })
      }
    }
  }
</script>